import {strict as assert} from 'assert'
import { toString62 } from 'num2str'

id_en = (r)=>
  for k, v of r
    switch typeof(v)
      when 'object'
        id_en(v)
      when 'number'
        r[k] = toString62 v
  return

key = (r, kind)=>
  id_en(r)
  if process.NODE_ENV != "production"
    _proxy = (k, prefix)=>
      _R = k
      k = new Proxy(
        _R
        get:(self, attr)=>
          if attr of self
            return self[attr]
          throw new Error("#{kind} key #{prefix}#{attr} undefined")
      )

    objmap = (o, prefix)=>
      for i of o
        if typeof(o[i]) == 'object'
          o[i] = objmap(o[i],prefix+i+".")
      _proxy o, prefix

    r = objmap r,""
  Object.freeze r

export default new Proxy(
  {}
  get:(self, attr)=>
    (o)=>
      key(o, attr)
)
